<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass="App\Repository\ShopRepository")
 */
class Shop
{
    /**
     * @Groups({"home","userEdit"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="shop", cascade={"persist", "remove"})
     * @ORM\JoinColumn(nullable=false)
     */
    private $user;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $logo;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $head;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="integer", nullable=true)
     */
    private $openStart;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="integer", nullable=true)
     */
    private $openEnd;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $province;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $city;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $area;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $address;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="text", nullable=true)
     */
    private $intro;

    /**
     * @Groups({"userEdit"})
     * @ORM\Column(type="array", nullable=true)
     */
    private $pics = [];

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="float", nullable=true)
     */
    private $lat;

    /**
     * @Groups({"home","userEdit"})
     * @ORM\Column(type="float", nullable=true)
     */
    private $lon;

    /**
     * @Groups({"userEdit","home"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $phone;

    /**
     * @ORM\Column(type="smallint", nullable=true)
     */
    private $isAuth;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\ShopAuth", mappedBy="shop", orphanRemoval=true)
     */
    private $auths;

    /**
     * @Groups({"tags","home"})
     * @ORM\ManyToMany(targetEntity="App\Entity\ShopTag",fetch="EAGER")
     */
    private $tags;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\ShopTagAppeal", mappedBy="shop", orphanRemoval=true)
     */
    private $tagAppeals;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="shop", orphanRemoval=true)
     */
    private $products;

    /**
     * @Groups({"home"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $openStr;

    /**
     * @Groups({"home"})
     * @ORM\OneToOne(targetEntity="App\Entity\ShopStatistic", mappedBy="shop", cascade={"persist", "remove"})
     */
    private $statistic;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\ShopCategoryApply", mappedBy="shop", orphanRemoval=true)
     */
    private $shopCategoryApplies;

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Category")
     */
    private $categories;

    public function __construct()
    {
        $this->auths = new ArrayCollection();
        $this->tags = new ArrayCollection();
        $this->tagAppeals = new ArrayCollection();
        $this->products = new ArrayCollection();
        $this->shopCategoryApplies = new ArrayCollection();
        $this->categories = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }

    public function setUser(User $user): self
    {
        $this->user = $user;

        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getLogo(): ?string
    {
        return $this->logo;
    }

    public function setLogo(?string $logo): self
    {
        $this->logo = $logo;

        return $this;
    }

    public function getHead(): ?string
    {
        return $this->head;
    }

    public function setHead(?string $head): self
    {
        $this->head = $head;

        return $this;
    }

    public function getOpenStart(): ?int
    {
        return $this->openStart;
    }

    public function setOpenStart(?int $openStart): self
    {
        $this->openStart = $openStart;

        return $this;
    }

    public function getOpenEnd(): ?int
    {
        return $this->openEnd;
    }

    public function setOpenEnd(?int $openEnd): self
    {
        $this->openEnd = $openEnd;

        return $this;
    }

    public function getProvince(): ?string
    {
        return $this->province;
    }

    public function setProvince(?string $province): self
    {
        $this->province = $province;

        return $this;
    }

    public function getCity(): ?string
    {
        return $this->city;
    }

    public function setCity(?string $city): self
    {
        $this->city = $city;

        return $this;
    }

    public function getArea(): ?string
    {
        return $this->area;
    }

    public function setArea(?string $area): self
    {
        $this->area = $area;

        return $this;
    }

    public function getAddress(): ?string
    {
        return $this->address;
    }

    public function setAddress(?string $address): self
    {
        $this->address = $address;

        return $this;
    }

    public function getIntro(): ?string
    {
        return $this->intro;
    }

    public function setIntro(?string $intro): self
    {
        $this->intro = $intro;

        return $this;
    }

    public function getPics(): ?array
    {
        return $this->pics;
    }

    public function setPics(?array $pics): self
    {
        $this->pics = $pics;

        return $this;
    }

    public function getLat(): ?float
    {
        return $this->lat;
    }

    public function setLat(?float $lat): self
    {
        $this->lat = $lat;

        return $this;
    }

    public function getLon(): ?float
    {
        return $this->lon;
    }

    public function setLon(?float $lon): self
    {
        $this->lon = $lon;

        return $this;
    }

    public function getPhone(): ?string
    {
        return $this->phone;
    }

    public function setPhone(?string $phone): self
    {
        $this->phone = $phone;

        return $this;
    }

    public function getIsAuth(): ?int
    {
        return $this->isAuth;
    }

    public function setIsAuth(?int $isAuth): self
    {
        $this->isAuth = $isAuth;

        return $this;
    }

    /**
     * @return Collection|ShopAuth[]
     */
    public function getAuths(): Collection
    {
        return $this->auths;
    }

    public function addAuth(ShopAuth $auth): self
    {
        if (!$this->auths->contains($auth)) {
            $this->auths[] = $auth;
            $auth->setShop($this);
        }

        return $this;
    }

    public function removeAuth(ShopAuth $auth): self
    {
        if ($this->auths->contains($auth)) {
            $this->auths->removeElement($auth);
            // set the owning side to null (unless already changed)
            if ($auth->getShop() === $this) {
                $auth->setShop(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|ShopTag[]
     */
    public function getTags(): Collection
    {
        return $this->tags;
    }

    public function addTag(ShopTag $tag): self
    {
        if (!$this->tags->contains($tag)) {
            $this->tags[] = $tag;
        }

        return $this;
    }

    public function removeTag(ShopTag $tag): self
    {
        if ($this->tags->contains($tag)) {
            $this->tags->removeElement($tag);
        }

        return $this;
    }

    /**
     * @return Collection|ShopTagAppeal[]
     */
    public function getTagAppeals(): Collection
    {
        return $this->tagAppeals;
    }

    public function addTagAppeal(ShopTagAppeal $tagAppeal): self
    {
        if (!$this->tagAppeals->contains($tagAppeal)) {
            $this->tagAppeals[] = $tagAppeal;
            $tagAppeal->setShop($this);
        }

        return $this;
    }

    public function removeTagAppeal(ShopTagAppeal $tagAppeal): self
    {
        if ($this->tagAppeals->contains($tagAppeal)) {
            $this->tagAppeals->removeElement($tagAppeal);
            // set the owning side to null (unless already changed)
            if ($tagAppeal->getShop() === $this) {
                $tagAppeal->setShop(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Product[]
     */
    public function getProducts(): Collection
    {
        return $this->products;
    }

    public function addProduct(Product $product): self
    {
        if (!$this->products->contains($product)) {
            $this->products[] = $product;
            $product->setShop($this);
        }

        return $this;
    }

    public function removeProduct(Product $product): self
    {
        if ($this->products->contains($product)) {
            $this->products->removeElement($product);
            // set the owning side to null (unless already changed)
            if ($product->getShop() === $this) {
                $product->setShop(null);
            }
        }

        return $this;
    }

    public function getOpenStr(): ?string
    {
        return $this->openStr;
    }

    public function setOpenStr(?string $openStr): self
    {
        $this->openStr = $openStr;

        return $this;
    }

    public function getStatistic(): ?ShopStatistic
    {
        return $this->statistic;
    }

    public function setStatistic(ShopStatistic $statistic): self
    {
        $this->statistic = $statistic;

        // set the owning side of the relation if necessary
        if ($statistic->getShop() !== $this) {
            $statistic->setShop($this);
        }

        return $this;
    }

    /**
     * @return Collection|ShopCategoryApply[]
     */
    public function getShopCategoryApplies(): Collection
    {
        return $this->shopCategoryApplies;
    }

    public function addShopCategoryApply(ShopCategoryApply $shopCategoryApply): self
    {
        if (!$this->shopCategoryApplies->contains($shopCategoryApply)) {
            $this->shopCategoryApplies[] = $shopCategoryApply;
            $shopCategoryApply->setShop($this);
        }

        return $this;
    }

    public function removeShopCategoryApply(ShopCategoryApply $shopCategoryApply): self
    {
        if ($this->shopCategoryApplies->contains($shopCategoryApply)) {
            $this->shopCategoryApplies->removeElement($shopCategoryApply);
            // set the owning side to null (unless already changed)
            if ($shopCategoryApply->getShop() === $this) {
                $shopCategoryApply->setShop(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Category[]
     */
    public function getCategories(): Collection
    {
        return $this->categories;
    }

    public function addCategory(Category $category): self
    {
        if (!$this->categories->contains($category)) {
            $this->categories[] = $category;
        }

        return $this;
    }

    public function removeCategory(Category $category): self
    {
        if ($this->categories->contains($category)) {
            $this->categories->removeElement($category);
        }

        return $this;
    }
}
